package com.zmn.oms.zmn.business.impl.product;

import com.zmn.base.product.common.dto.product.ec.ProductBaseDRO;
import com.zmn.base.product.dubbo.interfaces.channel.product.third.ChannelProductThirdListRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.model.dto.product.ChannelProductMapDTO;
import com.zmn.oms.zmn.business.interfaces.product.ProductMappingBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2021/02/03 19:05
 */
@Slf4j
@Service("productMappingBService")
public class ProductMappingBServiceImpl implements ProductMappingBService {

    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    protected ChannelProductThirdListRemoteService channelProductThirdListRemoteService;

    @Override
    public List<ChannelProductMapDTO> listChannelProductMapping(Integer channelId, String spuId, String skuId) {
        try {
            ResponseDTO<List<ProductBaseDRO>> responseDTO = channelProductThirdListRemoteService.listByChannelIdAndProductParentIdAndSubId(channelId, spuId, skuId);

            if (responseDTO.isSuccess() && CollectionUtils.isNotEmpty(responseDTO.getData())) {
                return BeanMapper.mapList(responseDTO.getData(), ChannelProductMapDTO.class);
            }
        } catch (Exception e) {
            log.error(String.format("查询渠道产品映射失败：%s，channelId=[%s], spuId=[%s], skuId=[%s]",
                    e.getMessage(), String.valueOf(channelId), String.valueOf(spuId), String.valueOf(skuId)), e);
        }
        return null;
    }
}
